<!DOCTYPE html>
<html>
#{include file="header.html"}#
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
  <div class="ibox float-e-margins">
    <div class="ibox-title">
      <h5><i class="fa fa-home"></i>客户详细</h5>
      <div class="ibox-tools">
        <button type="button" class="btn btn-xs btn-primary btn-back-reply"><i class="fa fa-reply"></i> 返回</button>
      </div>
    </div>
    <div class="ibox-content">
      <div class="row">
        <div class="col-sm-10">
          <div class="m-b-md">
            <h3>#{$one.name}#</h3>
          </div>
        </div>
        <div class="col-sm-2 text-right"> <a href="javascript:void(0)" class=" btn btn-default single_operation" data-id="#{$one.customer_id}#" data-act="modify"><i class="fa fa-edit"></i>修改</a> </div>
      </div>
      <div class="row">
        <div class="col-sm-6">
          <div class="ibox-content ">
            <p><strong>客户来源：</strong>#{$one.source_name}#</p>
            <p><strong>客户等级：</strong>#{$one.level_name}#</p>
            <p><strong>经济类型：</strong>#{$one.ecotype_name}#</p>
            <p><strong>行业类型：</strong>#{$one.trade_name}#</p>
            <p><strong>最近联系：</strong>#{$one.conn_time}#</p>
            <p><strong>联系内容：</strong>#{$one.conn_body}#</p>
            <p><strong>下次联系时间：</strong>#{$one.next_time}#</p>
          </div>
        </div>
        <div class="col-sm-6">
          <div class="ibox-content ">
            <p><strong>创建时间：</strong>#{$one.create_time}#</p>
            <p><strong>客户名称：</strong>#{$one.name}#</p>
            <p><strong>客户代表：</strong>#{$one.linkman}#</p>
            <p><strong>联系手机：</strong>#{$one.mobile}#</p>
            <p><strong>联系电话：</strong>#{$one.tel}#</p>
            <p><strong>联系邮箱：</strong>#{$one.email}#</p>
            <p><strong>联系地址：</strong>#{$one.address}#</p>
            <p><strong>客户介绍：</strong>#{$one.intro}#</p>
          </div>
        </div>
      </div>
      <div class="row m-t-sm">
        <div class="col-sm-12">
          <div class="panel blank-panel">
            <div class="panel-heading">
              <div class="panel-options">
                <ul class="nav nav-tabs">
                  <li class="active"><a href="?#tab-1" data-toggle="tab" >跟踪记录</a></li>
                  <li class=""><a href="?#tab-2" data-toggle="tab">联系人</a> </li>
                  <li class=""><a href="?#tab-3" data-toggle="tab">销售机会</a> </li>
                  <li class=""><a href="?#tab-4" data-toggle="tab">产品报价</a> </li>
                  <li class=""><a href="?#tab-5" data-toggle="tab">服务记录</a> </li>
                  <li class=""><a href="?#tab-6" data-toggle="tab">销售合同</a> </li>
                </ul>
              </div>
            </div>
            <div class="panel-body">
              <div class="tab-content">
                <div class="tab-pane active" id="tab-1">
                  <table class="table table-hover sorttable 07fly-table" width="100%">
                    <thead>
                      <tr>
                        <th><span>跟踪记录主题</span></th>
                        <th width="150"><span>最近联系时间</span></th>
                        <th width="150"><span>沟通内容</span></th>
                        <th width="150"><span>下次联系时间</span></th>
                        <th width="80"><span>沟通方式</span></th>
                        <th width="80"><span>当前阶段</span></th>
                      </tr>
                    </thead>
                    <tbody>
                    </tbody>
                  </table>
                  <table class="table 07fly-table">
                    <tfoot class="ibox-content">
                      <tr>
                        <td><a href="javascript:void(0)" class=" btn btn-xs btn-primary single_operation" data-id="#{$one.customer_id}#" data-act="trace">添加沟通记录</a></td>
                        <td align="center" class="pagestring"></td>
                      </tr>
                    </tfoot>
                  </table>
                </div>
                <div class="tab-pane" id="tab-2">
                  <table class="table table-hover sorttable 07fly-table" width="100%">
                    <thead>
                      <tr>
                        <th width="120"><span>姓名</span></th>
                        <th width="80"><span>性别</span></th>
                        <th width="120"><span>职位</span></th>
                        <th width="120"><span>手机</span></th>
                        <th width="120"><span>座机</span></th>
                        <th width="120"><span>QQ</span></th>
                      </tr>
                    </thead>
                    <tbody>
                    </tbody>
                  </table>
                  <table class="table 07fly-table">
                    <tfoot class="ibox-content">
                      <tr>
                        <td><a href="javascript:void(0)" class=" btn btn-xs btn-primary single_operation" data-id="#{$one.customer_id}#" data-act="linkman">添加联系人</a></td>
                        <td align="center" class="pagestring"></td>
                      </tr>
                    </tfoot>
                  </table>
                </div>
                <div class="tab-pane" id="tab-3">
                  <table class="table table-hover sorttable 07fly-table" width="100%">
                    <thead>
                      <tr>
                        <th><span>销售机会主题</span></th>
                        <th width="120"><span>发现时间</span></th>
                        <th width="120"><span>预计签单时间</span></th>
                        <th width="100"><span>预计金额</span></th>
                        <th width="80"><span>当前阶段</span></th>
                        <th width="120"><span>需求</span></th>
                      </tr>
                    </thead>
                    <tbody>
                    </tbody>
                  </table>
                  <table class="table">
                    <tfoot class="ibox-content">
                      <tr>
                        <td><a href="javascript:void(0)" class=" btn btn-xs btn-primary single_operation" data-id="#{$one.customer_id}#" data-act="chance">添加销售机会</a></td>
                        <td colspan="9" align="center"></td>
                      </tr>
                    </tfoot>
                  </table>
                </div>
                <div class="tab-pane" id="tab-4"> 功能开发中。。444。 </div>
                <div class="tab-pane" id="tab-5">
                  <table class="table table-hover sorttable 07fly-table" width="100%">
                    <thead>
                      <tr>
                        <th width="120"><span>服务类型</span></th>
                        <th width="120"><span>服务方式</span></th>
                        <th width="150"><span>服务时间</span></th>
                        <th width="100"><span>花费时间</span></th>
                        <th><span>服务内容</span></th>
                      </tr>
                    </thead>
                    <tbody>
                    </tbody>
                  </table>
                  <table class="table 07fly-table">
                    <tfoot class="ibox-content">
                      <tr>
                        <td><a href="javascript:void(0)" class=" btn btn-xs btn-primary single_operation" data-id="#{$one.customer_id}#" data-act="service">添加服务记录</a></td>
                        <td align="center" class="pagestring"></td>
                      </tr>
                    </tfoot>
                  </table>
                </div>
                <div class="tab-pane" id="tab-6">
                  <table class="table table-hover sorttable 07fly-table" width="100%">
                    <thead>
                      <tr>
                        <th><span>合同主题</span></th>
                        <th width="100"><span>合同金额</span></th>
                        <th width="120"><span>回款/金额/状态</span></th>
                        <th width="120"><span>发票/金额/状态</span></th>
                        <th width="100"><span>开始时间</span></th>
                        <th width="100"><span>结束时间</span></th>
                        <th width="80"><span>合同状态</span></th>
                      </tr>
                    </thead>
                    <tbody>
                    </tbody>
                  </table>
                  <table class="table">
                    <tfoot class="ibox-content">
                      <tr>
                        <td><a href="javascript:void(0)" class=" btn btn-xs btn-primary single_operation" data-id="#{$one.customer_id}#" data-act="contract">添加销售合同</a></td>
                        <td colspan="10" align="center"></td>
                      </tr>
                    </tfoot>
                  </table>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
</html>
<script id="tab-1-Tpl" type="text/html">
<% for(var i=0;i<list.length;i++) { %>
	<tr>
		<td><%=list[i]['name']%><br><small>(创建：<%=list[i]['create_time']%>)</small></td>
		<td><%=list[i]['conn_time']%></td>
		<td class="overflow-td"><%=list[i]['intro']%></td>	
		<td><%=list[i]['next_time']%></td>
		<td><%=list[i]['salemode_name']%></td>
		<td><%=list[i]['salestage_name']%></td>	
		<td width='10'>	</td>
	</tr>
<% } %>
</script>
<script id="tab-2-Tpl" type="text/html">
<% for(var i=0;i<list.length;i++) { %>
	<tr>
		<td><%=list[i]['name']%></td>
		<td>
			<%if(list[i]['gender']=1){%>
			 	男
			<%}else{%> 
			 	女
			<%}%> 
		</td>
		<td><%=list[i]['postion']%></td>
		<td><%=list[i]['mobile']%></td>
		<td><%=list[i]['tel']%></td>
		<td><%=list[i]['qicq']%></td>		
	</tr>
<% } %>
</script>
<script id="tab-3-Tpl" type="text/html">
<% for(var i=0;i<list.length;i++) { %>
	<tr>
		<td><%=list[i]['name']%><br><small>(创建：<%=list[i]['create_time']%>)</small></td>
		<td><%=list[i]['find_date']%></td>
		<td><%=list[i]['bill_date']%></td>
		<td><%=list[i]['money']%></td>
		<td><%=list[i]['salestage_name']%></td>
		<td class="overflow-td"><%=list[i]['intro']%></td>
	</tr>
<% } %>
</script>
<script id="tab-4-Tpl" type="text/html">
<% for(var i=0;i<list.length;i++) { %>
	<tr>
		<td><%=list[i]['name']%><br><small>(创建：<%=list[i]['create_time']%>)</small></td>
		<td><%=list[i]['conn_time']%></td>
		<td class="overflow-td"><%=list[i]['intro']%></td>	
		<td><%=list[i]['next_time']%></td>
		<td><%=list[i]['salemode_name']%></td>
		<td><%=list[i]['salestage_name']%></td>	
		<td width='10'>	</td>
	</tr>
<% } %>
</script>
<script id="tab-5-Tpl" type="text/html">
<% for(var i=0;i<list.length;i++) { %>
	<tr>
		<td><%=list[i]['services_name']%></td>
		<td><%=list[i]['servicesmodel_name']%></td>
		<td><%=list[i]['service_time']%></td>
		<td><%=list[i]['tlen']%></td>
		<td class="overflow-td"><%=list[i]['content']%></td>	
	</tr>
<% } %>
</script>
<script id="tab-6-Tpl" type="text/html">
<% for(var i=0;i<list.length;i++) { %>
	<tr>
		<td><%=list[i]['title']%><br><small>(创建：<%=list[i]['create_time']%>)</small></td>
		<td><%=list[i]['money']%></td>
		<td>
			
			回款：<%=list[i]['back_money']%><br>
			去零：<%=list[i]['zero_money']%><br>
			欠款：<%=list[i]['owe_money']%><br>
			状态：<font color="<%=list[i]['back_status_arr']['color']%>"><%=list[i]['back_status_arr']['status_name']%></font>
	
		</td>
		<td>
			开票：<%=list[i]['invoice_money']%><br>
			状态：<font color="<%=list[i]['invoice_status_arr']['color']%>"><%=list[i]['invoice_status_arr']['status_name']%></font>	
		</td>
		<td><%=list[i]['start_date']%></td>
		<td><%=list[i]['end_date']%></td>
		<td><%:=list[i]['status_arr']['status_name_html']%></td>	
	</tr>
<% } %>
  <tr>
	<td colspan="7" align="left">
		合同金额合计：<span class="text-danger">&yen;<%=countMoney['total_money']%></span>&nbsp;&nbsp;
		回款金额合计：<span class="text-danger">&yen;<%=countMoney['total_back_money']%></span>&nbsp;&nbsp;
		欠款金额合计：<span class="text-danger">&yen;<%=countMoney['total_owe_money']%></span>&nbsp;&nbsp;
	
	</td>
  </tr>
</script>
<script src="#{$smarty.const.APP}#/View/template/js/content.js?v=1.0.0"></script>
<script type="text/javascript">
$(document).ready(function () {
	
	$('.nav-tabs li').each( function( index, val ) {
		var tabl_index=index+1;
		ajax_customer_detail(tabl_index);
	});


	$("body").on("click", ".single_operation", function() {
		customer_id =$(this).attr("data-id");
		single_act =$(this).attr("data-act")
		if(single_act=="modify"){
			act_url="#{$smarty.const.ACT}#/index.php/crm/CstCustomer/cst_customer_modify/";
			layer.open({
				type: 2,
				title: '修改客户信息',
				shadeClose: true,
				fixed: false, //不固定
				area: ['90%', '90%'],
				content: '#{$smarty.const.ACT}#/index.php/crm/CstCustomer/cst_customer_modify/customer_id/'+customer_id+'/',
				end: function () {
             location.reload();
           }
			});			
			return false;	
		}else if(single_act=="linkman"){
			act_url="#{$smarty.const.ACT}#/index.php/crm/CstLinkman/cst_linkman_add/";
			layer.open({
				type: 2,
				title: '添加联系人',
				shadeClose: true,
				fixed: false, //不固定
				area: ['800px', '500px'],
				content: '#{$smarty.const.ACT}#/index.php/crm/CstLinkman/cst_linkman_add/customer_id/'+customer_id+'/',
				end: function () {
             ajax_customer_detail(2);
           }
			});			
			return false;	
		}else if(single_act=="service"){
			layer.open({
				type: 2,
				title: '添加服务记录',
				shadeClose: true,
				fixed: false, //不固定
				area: ['800px', '500px'],
				content: '#{$smarty.const.ACT}#/index.php/crm/CstService/cst_service_add/customer_id/'+customer_id+'/',
				end: function () {
             ajax_customer_detail(5);
           }
			});			
			return false;
		}else if(single_act=="chance"){
			layer.open({
				type: 2,
				title: '添加销售机会',
				shadeClose: true,
				fixed: false, //不固定
				area: ['800px', '500px'],
				content: '#{$smarty.const.ACT}#/index.php/crm/CstChance/cst_chance_add/customer_id/'+customer_id+'/',
				end: function () {
             ajax_customer_detail(3);
           }
			});			
			return false;
		}else if(single_act=="contract"){
			layer.open({
				type: 2,
				title: '添加销售合同',
				shadeClose: true,
				fixed: false, //不固定
				area: ['800px', '500px'],
				content: '#{$smarty.const.ACT}#/crm/SalContract/sal_contract_add/customer_id/'+customer_id+'/',
				end: function () {
             ajax_customer_detail(6);
           }
			});			
			return false;
		}else if(single_act=="trace"){
			layer.open({
				type: 2,
				title: '添加沟通记录',
				shadeClose: true,
				fixed: false, //不固定
				area: ['800px', '500px'],
				content: '#{$smarty.const.ACT}#/index.php/crm/CstTrace/cst_trace_add/customer_id/'+customer_id+'/',
				end: function () {
             ajax_customer_detail(1);
           }
			});			
			return false;
		}else if(single_act=="del"){
			act_url="#{$smarty.const.ACT}#/index.php/crm/CstCustomer/cst_customer_del/";
			$.ajax({
				type: "POST",
				url: act_url,
				data:{"customer_id":customer_id},
				dataType:"json",
				async: false,
				success: function(data){
					if(data.statusCode=='200'){
						layer.msg('操作成功', {icon: 1}); 
						setTimeout(function(){
							turnPage(1);
						 },800);
					}
				}
			});
			return false;
		}else if(single_act=="detail"){
			act_url="#{$smarty.const.ACT}#/crm/CstCustomer/cst_customer_detail/customer_id/"+customer_id+"/";
			window.location.href=act_url;
		}else if(single_act=="offline"){
			act_url="#{$smarty.const.ACT}#/index.php/crm/CstCustomer/cst_customer_modify_offline/";
		}
	});

	
});
//加载客户业务信息
function ajax_customer_detail(tabl_index){
	if(tabl_index==1){
	   var ajax_url="#{$smarty.const.ACT}#/crm/CstTrace/cst_trace_json/";
		$.ajax({
			type: "POST",
			url: ajax_url,
			data:{"customer_id":"#{$one.customer_id}#","pageSize":"1000"},
			dataType:"json",
			success: function(returnJsonData){
				var tpl=baidu.template;
				var html=tpl('tab-'+tabl_index +'-Tpl',returnJsonData);
				$("#tab-"+ tabl_index +" tbody").html(html);
			}, 
		});
	}else if(tabl_index==2){
		var ajax_url="#{$smarty.const.ACT}#/crm/CstLinkman/cst_linkman_json/";
		$.ajax({
			type: "POST",
			url: ajax_url,
			data:{"customer_id":"#{$one.customer_id}#","pageSize":"1000"},
			dataType:"json",
			success: function(returnJsonData){
				var tpl=baidu.template;
				var html=tpl('tab-'+tabl_index +'-Tpl',returnJsonData);
				$("#tab-"+ tabl_index +" tbody").html(html);
			}, 
		});
	}else if(tabl_index==3){
		var ajax_url="#{$smarty.const.ACT}#/crm/CstChance/cst_chance_json/";
		$.ajax({
			type: "POST",
			url: ajax_url,
			data:{"customer_id":"#{$one.customer_id}#","pageSize":"1000"},
			dataType:"json",
			success: function(returnJsonData){
				var tpl=baidu.template;
				var html=tpl('tab-'+tabl_index +'-Tpl',returnJsonData);
				$("#tab-"+ tabl_index +" tbody").html(html);
			}, 
		});
	}else if(tabl_index==4){
		var ajax_url="#{$smarty.const.ACT}#/crm/CstTrace/cst_trace_json/";	 
		$.ajax({
			type: "POST",
			url: ajax_url,
			data:{"customer_id":"#{$one.customer_id}#","pageSize":"1000"},
			dataType:"json",
			success: function(returnJsonData){
				var tpl=baidu.template;
				var html=tpl('tab-'+tabl_index +'-Tpl',returnJsonData);
				$("#tab-"+ tabl_index +" tbody").html(html);
			}, 
		});
	}else if(tabl_index==5){
		var ajax_url="#{$smarty.const.ACT}#/crm/CstService/cst_service_json/";
		$.ajax({
			type: "POST",
			url: ajax_url,
			data:{"customer_id":"#{$one.customer_id}#","pageSize":"1000"},
			dataType:"json",
			success: function(returnJsonData){
				var tpl=baidu.template;
				var html=tpl('tab-'+tabl_index +'-Tpl',returnJsonData);
				$("#tab-"+ tabl_index +" tbody").html(html);
			}, 
		});
	}else if(tabl_index==6){
		var ajax_url="#{$smarty.const.ACT}#/crm/SalContract/sal_contract_json/";
		$.ajax({
			type: "POST",
			url: ajax_url,
			data:{"customer_id":"#{$one.customer_id}#","pageSize":"1000"},
			dataType:"json",
			success: function(returnJsonData){
				var tpl=baidu.template;
				var html=tpl('tab-'+tabl_index +'-Tpl',returnJsonData);
				$("#tab-"+ tabl_index +" tbody").html(html);
			}, 
		});
	}
	console.log(ajax_url);
}
</script>